<?php

include_once($_SERVER['DOCUMENT_ROOT']."/RecJP/inc/usedb_inc.php");

class DAL_LeaveMessage {

    public static function GetMessageList() {
        $sql = "SELECT * FROM leavemessage";
        $Message = getSqliteHelper()->Query($sql, null);
        return $Message;
    }

    public static function insertMessage($leaveMessage) {
        $p = array(":userid" => $leaveMessage->userid, ":username" => $leaveMessage->username,
            ":message" => $leaveMessage->message, ":ip" => $leaveMessage->ip, ":inserttime" => $leaveMessage->inserttime);

        if ($leaveMessage->userid != null && $leaveMessage->userid != "") {
            $p[":userid"] = $leaveMessage->userid;
        }
        if ($leaveMessage->username != null && $leaveMessage->username != "") {
            $p[":username"] = $leaveMessage->username;
        }if ($leaveMessage->message != null && $leaveMessage->message != "") {
            $p[":message"] = $leaveMessage->message;
        }if ($leaveMessage->ip != null && $leaveMessage->ip != "") {
            $p[":ip"] = $leaveMessage->ip;
        }
        if ($leaveMessage->inserttime != null && $leaveMessage->inserttime != "") {
            $p[":inserttime"] = $leaveMessage->inserttime;
        }

        $cols = "";
        $val = "";
        foreach ($p as $key => $value) {
            $cols.=trim($key, ":") . ",";
            $val.=$key . ",";
        }
        $cols = trim($cols, ",");
        $val = trim($val, ",");

        $sql = "insert into leavemessage ($cols) values($val)";

        //echo $sql;

        $s = new SqliteHelper();
        $s->ExecNoTans($sql, $p);
    }

}

?>
